
desc:ForRetroRec(MIDI) v20151213
slider1:0<0,8388608,1>-MSG_Count
slider2:0<0,2097151,1>-MSG_Number
slider3:0<-4096,65536,0.001>-MSG_Position
slider4:0<0,256,1>-msg1
slider5:0<0,127,1>-msg2
slider6:0<0,127,1>-msg3
slider7:1<0,1,1{No(As Rec Out Mode),Yes(As Rec Normal Mode)}>Compensate Latency
slider8:0<0,1,1{Only when you press Play,At each change of Playposition}>ReWrite Buffer
slider9:0<0,8192,1>-data
in_pin:none
out_pin:none
@slider 
slider1 = input_msg_count;//MSG_Count(1-based)
si = slider2*4;
slider3=buf[si];//MSG_Position
slider4=buf[si+1];slider5=buf[si+2];slider6=buf[si+3];//msg1,msg2,msg3
@init
ext_noinit=1;//only execute on load or samplerate change
buf=0;//buf offset for MSG-data
others=8388600;//buf offset for other data
@block
Start_Play_Position = play_position;//B_start
//==========Reset Counters==========//
  slider9==8192 ? (i=0; j=0; others[5]=0; others[6]=0; slider9=0;);//i,j,msg_count,item_count=0 if val=8192
 (play_state==0 || (slider8>0 && abs(Start_Play_Position-Last_Play_Position)>0.125) ) ?
                   (i = 0; j=0; others[4]=samplesblock/srate; );//Reset i,j;//save sblock/srate
//==========Save start-end points for each Item============//
 ((play_state==1 || play_state == 5) && abs(Start_Play_Position-Last_Play_Position)>0.125) ?
               (i>=4  ? (           //===END Prev Item===//
                          buf[i] = Last_Play_Position;//Special Info = Prev item End Pos
                          buf[i+1] = -2; //msg2 As special Info = -2 = Prev item End Pos
                          buf[i+2]=j/4;  //msg2 As special Info = Item Number(0-based)
                          i+=4;j+=4;
                                    //===Start New Item===//s
                          buf[i] = Start_Play_Position;//Special Info = New item Start Pos
                          buf[i+1] = -1; //msg1 As special Info = -1 = New item Start Pos
                          buf[i+2]=j/4;  //msg2 As special Info = Item Number(0-based)
                          i+=4;
                          item_count+=1;
                          input_msg_count+=2; slider1 = input_msg_count;//Update Slider MSG_Count
                          others[6]=item_count;//Update others[6]=item_count
                         );
                others[6]=item_count;//Update others[6]=item_count when pos Changed
               );
//===Save each position and msg1,msg2,msg3 to buf[.,.,.,.]===// 
  play_state == 1 || play_state == 5 ? //1=play-main mode,5=rec-only for check!
   (while (midirecv(offset,msg1,msg2,msg3) )
             (i==0 ? (input_msg_count=0;item_count=1;);//Reset msg & item_count ONLY wh i=0 & NEW midirecvied
              input_msg_count+=1; slider1 = input_msg_count;//Update Slider MSG_Count
              buf[i] = Start_Play_Position + offset/srate;//Pos w offset:(1/srate)*offset
              buf[i+1] = msg1;
              buf[i+2] = msg2;
              buf[i+3] = msg3;
                others[5]=input_msg_count;//Update buf[others+5]=input_msg_count
                others[6]=item_count;//Update others[6]=item_count when Msg recvied
              i+=4;
              midisend(offset,msg1,msg2,msg3);//Pass true
              );
   );
Last_Play_Position = Start_Play_Position+samplesblock/srate;;//B_end

